/**
* leveldb cpp 类导入声明
* 还未完成
*/
module leveldb.cpp;

import std.stdint;

//alias Handle = void*;

extern(C++,leveldb) {
    struct Options;
    struct ReadOptions;
    struct WriteOptions;

    /**
    * 由 slice.h 导入代码
    */
    class Slice{
        private{
            char* data_;
            size_t size_;
        }
    }
    

    abstract class Cache{
        public{
            struct Handle;

            @disable this();
            ~this();
        }
        private{
            struct Rep;
            void LRU_Remove(Handle* e);
            void LRU_Append(Handle* e);
            void Unref(Handle* e);
            Rep* rep_;
        }
    }

    Cache NewLRUCache(size_t);

}

version(NONE):

private:
extern(C++,leveldb) {

    /**
    * 由 status.h 导入代码
    */
    class Status
    {
        public:

    }
    /**
    * 由 iterator.h 导入代码
    */
    abstract class Iterator {
        struct CleanupNode{
            CleanupFunction fun;
            void* arg1;
            void* arg2;
            typeof(this)* next;
            public:
            bool IsEmpty()
            {
                return (fun is null);
            }
            void Run()
            {
                if(fun !is null)
                {
                    fun(arg1,arg2);
                }
            }
        }

        public:
        @disable this();
        ~this();
        bool Valid();
        /// 定位到数据头部key
        void SeekToFirst();
        /// 定位到数据尾部key
        void SeekToLast();
        /// 定位到指定的key
        void Seek(ref Slice target);
        /// 定位到下一个`key`,对比较`Prev()`性能好
        void Next();
        /// 定位到上一个`key`,对比较'Next()'性能差
        void Prev();
        /// 返回当前`key`
        Slice key();
        /// 返回当前`key`对应的`value`
        Slice value();
        /// 返回当前状态
        Status status();
        /// 迭代器清理函数
        alias CleanupFunction=void* function(void* v1,void* v2 );
        //void* function(void* v1,void* v2 ) CleanupFunction;
        /// 注册迭代器清理函数
        void RegisterCleanup(CleanupFunction fun,void* arg1,void* arg2);
        CleanupNode cleanup_head_;
    }
    
    Iterator NewEmptyIterator();
    Iterator NewErrorIterator(ref Status s);
}


